#include <bits/stdc++.h>
using namespace std;
int a[1005],v[1005],d[1005],dc[1005],num[1005];
int vis[1005][1005];
int ans3[1005],ans4[1005];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    int abc = 0;
    cin >> T;
    while(T--)
    {
        int n,m,L,V;
        cin >> n >> m >> L >> V;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                vis[i][j] = 0;
            }
        }
        
        for(int i = 1; i <= n; i++)
        {
            cin >> d[i] >> v[i] >> a[i];
        }
        for(int i = 1; i <= m ; i++)
        {
            cin >> dc[i];
        }
        
        for(int i = 1; i <= n ; i++)
        {
            double d1 = (pow(V,2) - pow(v[i],2)) / (2 * a[i]) + d[i];
            if(d1 < d[i])
            {
                d1 = d[i];
            }
            if(a[i] > 0) 
            {
                for(int j = 1; j <= m ; j++)
                {
                    if(dc[j] > d1)
                    {
                        vis[i][j] = 1;
                    }
                }
            }
            else if(a[i] == 0)
            {
                if(v[i] > V)
                {
                   for(int j = 1; j <= m ; j++)
                    {
                        if(dc[j] > d[i])
                        {
                            vis[i][j] = 1;
                        }
                    } 
                }
            }
            else if(a[i] < 0 && v[i] < V)
            {
                for(int j = 1; j <= m ; j++)
                {
                    vis[i][j] = 0;
                }
            }
            else
            {
                for(int j = 1; j <= m; j++)
                {
                    if(dc[j] >= d[i] && dc[j] < d1)
                    {
                        vis[i][j] = 1;
                    }
                }
            }
            
        }
      
        int ans1 = n,x = n;
        for(int i = 1; i <= n; i++)
        {
            int cnt = 0;
            for(int j = 1; j <= m; j++)
            {
                if(vis[i][j] == 1)
                {
                    cnt = 1;
                }
            }
            if(cnt == 0)
            {
                ans1--;
                x--;
            }
        }
        
        int ans2 = 0;
        for(int i = 1; i <= n; i++)
        {
            int jsq = 0;
            int b;
            for(int j = 1; j <= m; j++)
            {
                if(vis[i][j] == 1)
                {
                    b = j;
                    jsq++;
                }
            }
            if(jsq == 1)
            {
                
                ans2++;
                for(int i = 1; i <= n ; i++)
                {   
                    if(vis[i][b] == 1)
                    {
                        x--;
                        for(int j = 1; j <= m;j++)
                       {
                           vis[i][j] = 0;
                        }
                    }
                    
                }
                
            }
        }
        
        for(int j = 1; j <= m; j++)
        {
            num[j] = 0;
        }
        for(int i = 1; i <= n ; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                if(vis[i][j] == 1)
                {
                    num[j]++;
                }
            }
        }
       
        while(x > 0)
        {
            int maxn = 0;
            int maxnn;
            for(int j = 1; j <= m ; j++)
            {
                if(num[j] > maxn)
                {
                    maxn = num[j];
                    maxnn = j;
                }
            }
            num[maxnn] = 0;
            //cout << maxnn << '\n';
            for(int i = 1;i <= n ; i++)
            {
                if(vis[i][maxnn] == 1)
                {
                    x -= 1;
                   // cout << i << " ";
                    for(int j = 1; j <= m ; j++)
                    {
                        if(vis[i][j] == 1)
                        {
                            vis[i][j] = 0;
                            num[j] -= 1;
                        }
                        
                    }
                    
                }
            }
    
            //for(int i = 1; i <= n ; i++)
            //{
                //for(int j = 1; j <= m ; j++)
                //{
                   // cout << vis[i][j] << " ";
                //}
                //cout << '\n';
            //}
            ans2++;
            
        }
        abc++;
        ans3[abc] = ans1;
        ans4[abc] = n - ans2;
        
    }
    for(int i = 1; i <= abc; i++)
    {
        cout << ans3[i] << " " << ans4[i] << '\n';
    }
    return 0;
}
